<?php

namespace app\web\service;

use app\common\util\Tools;
use think\Paginator;

/**
 * Class BaseService
 * @package app\web\service
 * 服务类
 */
abstract class BaseService
{
    protected $params;
    protected $returnData;
    protected $mall_id = 0;

    public function __construct($data, $params)
    {
        $this->returnData = $data;
        $this->params = $params;
        $this->mall_id = request()->mallData["id"];
    }

    public function convertPageData(Paginator $data, $isHump = true){
        $data = $data->toArray();
        if($data["data"]){
            $items = !$isHump ? $data["data"] : Tools::transferFields($data["data"]);
        }else{
            $items = [];
        }
        return ['list' => $items, 'totalPage' => $data["last_page"], 'currentPage' => $data["current_page"], 'count' => $data["total"]];
    }

    public function convertData(array $data, $isHump = true){
        return !$isHump ? $data : Tools::transferFields($data);
    }
}